import { message } from 'antd'
import axios from 'axios'

export default (url, data={}, type='GET') => {
    return new Promise((resolve, reject) => {
        let promise 
        if(type === 'GET'){
            promise = axios.get(url, {
                params:data
            })
        }else{
            promise = axios.post(url, data)
        }

        promise.then((res) => {
            resolve(res.data)
        }).catch((error) => {
            message.error('请求发生错误'+error.message)
        })
    })
}

// axios.interceptors.request.use(function (config) {
//     //console.log('request interceptors:',config)
//     return config;
//   }, function (error) {
//     return Promise.reject(error);
//   });

//   axios.interceptors.response.use(function (response) {
//     console.log('response interceptors:',response.data)
//     return response.data;
//   }, function (error) {
//       console.log('response interceptors:',error)
//     return Promise.reject(error);
//   });